package com.example.musicwebcon.service;

import com.example.musicwebcon.model.dto.localDTO;
import com.example.musicwebcon.model.localSong;
import com.example.musicwebcon.repository.localRepository;
import com.example.musicwebcon.service.serviceInterface.IlocalService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class localService implements IlocalService {
    @Autowired
    localRepository localRepository;
    @Override
    public localSong add(localDTO localSong) {
        localSong localsong = new localSong();
        BeanUtils.copyProperties(localSong,localsong);
        return localRepository.save(localsong);
    }

    @Override
    public localSong getMusicId(String musicId) {
        return localRepository.findById(musicId).orElseThrow(() -> {
            throw new IllegalArgumentException("歌曲不存在，参数异常！");
        });
    }

    @Override
    public Iterable<localSong> getALl() {
        return localRepository.findAll();
    }

    @Override
    public localSong edit(localDTO localSong) {
        localSong localsong = new localSong();
        BeanUtils.copyProperties(localSong,localsong);
        return localRepository.save(localsong);
    }

    @Override
    public void deleteMusicId(String musicId) {localRepository.deleteById(musicId);}
}
